home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 103 / CD-ROM 103.iso / edu / martianwin / src / menu.h < prev    next >
Encoding:
Text File  |  2003-08-11  |  2.1 KB  |  65 lines

  1. /*
  2.     Funcion para realizar menues para una aplicacion
  3.     Parametros:
  4.     ---------------------------------------------------------------------
  5.     |  x            | posicion x del comienzo del menu en la pantalla   |
  6.     |  y            | posicion y del comienzo del menu en la pantalla   |
  7.     |  inactivefont | font a utilizar para las opciones no selecionadas |
  8.     |  activefont   | font a utilizar para la opcion selecionada        |
  9.     |  spacing      | separacion entre una opcion y la siguiente        |
  10.     |  optionsc     | cantidad de opciones en el menu                   |
  11.     |  options      | el texto de cada opcion                           |
  12.     |  pos          | opcion activa en el menu al inicio                |
  13.     ---------------------------------------------------------------------
  14. */
  15.  
  16. SDL_Surface *back;
  17.  
  18. int menu(int x, int y, SDL_Surface * inactivefont, SDL_Surface * activefont, int spacing, int optionc, char *option[], int pos)
  19. {
  20.     SDL_Surface * font;
  21.     SDL_Event event;
  22.  
  23.     while(true)
  24.     {
  25.     // --- chequeamos el mouse ATENCION!!! esto es especifico de cada menu NO ES ESTANDAR PARA TODOS LOS PROYECTOS
  26.     int mouse_x, mouse_y;
  27.     SDL_GetMouseState(&mouse_x, &mouse_y);
  28.     int oldpos=pos;
  29.     if(mouse_x>=280 && mouse_x<=389 && mouse_y>=200 && mouse_y<=227)
  30.         pos=1;
  31.     if(mouse_x>=168 && mouse_x<=473 && mouse_y>=235 && mouse_y<=262)
  32.         pos=2;
  33.     if(mouse_x>=252 && mouse_x<=417 && mouse_y>=270 && mouse_y<=297)
  34.         pos=3;
  35.     if(mouse_x>=280 && mouse_x<=389 && mouse_y>=305 && mouse_y<=332)
  36.         pos=4;
  37.  
  38.     if(pos!=oldpos) Mix_PlayChannel(1, option_sound,0);
  39.  
  40.     int n;
  41.     for(n=0;n<optionc;n++)
  42.     {
  43.         if(n+1==pos)
  44.         font=inactivefont;
  45.         else
  46.         font=activefont;
  47.  
  48.         int fw=font->w/91;
  49.         int fh=font->h;
  50.  
  51.         T_Print(font, x, (y+(n*spacing)), "%s",option[n]);
  52.         SDL_UpdateRect(screen,x, (y+(n*spacing)), (fw*(strlen(option[n]))), fh);
  53.         SDL_Delay(5);
  54.         while(SDL_PollEvent(&event))
  55.         if(event.type==SDL_QUIT) return(4);
  56.         if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT)
  57.         {
  58.             Mix_PlayChannel(1,option_sound,0);
  59.             return(pos);
  60.         }
  61.     }
  62.     }
  63. }
  64.  
  65.